/*ans = p + q - gcd(p, q)*/

#include <stdio.h>
#include <stdlib.h>

int gcd(int p, int q)
{
    int t;

    while (q != 0) {
        t = p % q;
        p = q;
        q = t;
    }

    return p;
}

int main (int argc, char const* argv[])
{
    int ans, p, q;

    while (scanf("%d %d", &p, &q) != EOF) {
        ans = p + q - gcd(p, q);
        printf("%d\n", ans);
    }

    return 0;
}
